<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .big-box{
            width: 500px;
            height: 30px;
            border: 1px solid#000;
        }
        .small-box{
            width: 0;
            height: 30px;
            background-color: red;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="big-box">
        <div class="small-box">
            <span>0</span><span>%</span>
        </div>
    </div>
    <button id="btn">安装</button>
</body>
<script>
    var div = document.getElementsByTagName('div');
    var span = document.getElementsByTagName('span');
    var btn = document.getElementById('btn')
    var timer = null;

    btn.onclick = function(){
        var num = 0;
        if(timer === null){
            timer = setInterval(() => {
                num +=1;
                div[1].style.width = num + 'px';
                span[0].innerText = Math.ceil( num/500  * 100);
                if(num === 500){
                    clearInterval(timer);
                }
            },10)
        }
    }
</script>
</html>